package com.fan.shop.businesslogic;

import org.apache.log4j.Logger;

import com.fan.shop.domain.StockReqLine;
import com.fan.shop.global.ShopGlobalVariables;
import com.fan.shop.process.ProcExec;
import com.fan.shop.services.StockReqLineService;

public class StockReqLineCancelProcess extends ProcExec<Integer> {

	private static Logger logger = Logger
			.getLogger(StockReqLineCancelProcess.class);

	private String requisitionNo;
	private String itemCode;

	private StockReqLineService stockReqLineService;

	public static Logger getLogger() {
		return logger;
	}

	public static void setLogger(Logger logger) {
		StockReqLineCancelProcess.logger = logger;
	}

	public String getRequisitionNo() {
		return requisitionNo;
	}

	public void setRequisitionNo(String requisitionNo) {
		this.requisitionNo = requisitionNo;
	}


	public String getItemCode() {
		return itemCode;
	}

	public void setItemCode(String itemCode) {
		this.itemCode = itemCode;
	}

	public StockReqLineService getStockReqLineService() {
		return stockReqLineService;
	}

	public void setStockReqLineService(StockReqLineService stockReqLineService) {
		this.stockReqLineService = stockReqLineService;
	}

	@Override
	public Integer processImpl() {
		if(!stockReqLineService.hasStockReqLine(requisitionNo, itemCode))
		{
			setErrorMessage("Requisition Line: " + requisitionNo + " " + itemCode + " doesn't exist!");
			return ShopGlobalVariables.FAILED;
		}
		
		StockReqLine stockReqLine = stockReqLineService.getStockReqLine(requisitionNo, itemCode);
		stockReqLine.setLineStatus(ShopGlobalVariables.CANCELLED);
		
		stockReqLineService.updateStockReqLine(stockReqLine);
		
		return ShopGlobalVariables.SUCCESS;
	}

}
